
<html><HEAD>
<LINK REL=STYLESHEET HREF="default.css" TYPE="text/css">
<TITLE>
Exception handling</TITLE>
</HEAD>
<BODY>

<!-- Header -->
<p class="ancestor" align="right"><A HREF="apptechp186.htm">Previous</A>&nbsp;&nbsp;<A HREF="apptechp188.htm" >Next</A>
<!-- End Header -->
<A NAME="CCJBBGBCA"></A><h1>Exception handling</h1>
<A NAME="TI5675"></A><p>Errors that occur
in the execution of a method of an EJB component are mapped to exception
proxies and thrown to the calling script. The methods of all the
classes in <i>pbejbclient115.pbx</i> can also throw
exceptions when, for example, connection to the server fails or
the component cannot be located or created.</p>
<A NAME="TI5676"></A><p>Building EJB proxy projects generates the proxies for the
home and remote interfaces, proxies for any Java classes referenced
by the EJB, proxies for ancestor classes, and proxies for any exceptions
that can be thrown by the EJB and its supporting classes. The following
exception proxies are among those that may display in the System
Tree:</p>
<A NAME="TI5677"></A><table cellspacing=0 cellpadding=6 border=1 frame="void" rules="all"><tr><th  rowspan="1"  ><A NAME="TI5678"></A>Proxy name</th>
<th  rowspan="1"  ><A NAME="TI5679"></A>Java object name</th>
</tr>
<tr><td  rowspan="1"  ><A NAME="TI5680"></A>createexception</td>
<td  rowspan="1"  ><A NAME="TI5681"></A>javax.ejb.CreateException</td>
</tr>
<tr><td  rowspan="1"  ><A NAME="TI5682"></A>ejbexception</td>
<td  rowspan="1"  ><A NAME="TI5683"></A>javax.ejb.EJBException</td>
</tr>
<tr><td  rowspan="1"  ><A NAME="TI5684"></A>finderexception</td>
<td  rowspan="1"  ><A NAME="TI5685"></A>javax.ejb.FinderException</td>
</tr>
<tr><td  rowspan="1"  ><A NAME="TI5686"></A>remoteexception</td>
<td  rowspan="1"  ><A NAME="TI5687"></A>java.rmi.RemoteException</td>
</tr>
<tr><td  rowspan="1"  ><A NAME="TI5688"></A>removeexception</td>
<td  rowspan="1"  ><A NAME="TI5689"></A>javax.ejb.RemoveException</td>
</tr>
</table>
<A NAME="TI5690"></A><h4>Catching exceptions</h4>
<A NAME="TI5691"></A><p>A client application can handle communications errors in a
number of ways. For example, if a client connects to a server and
tries to invoke a method for an object that does not exist, the
client can disconnect from the server, connect to a different server,
or retry the operation. Alternatively, the client can display a message
to the user and give the user the opportunity to control what happens next.</p>
<A NAME="TI5692"></A><p>When an error occurs, if the client connects to a new server
to retry the operation, it must instantiate the remote object on
the new server before invoking a method of the remote object.</p>
<A NAME="TI5693"></A><p>In the following example, the script simply displays a message
box when a specific exception occurs:<p><PRE> // function char getChar() throws RemoteException<br>try<br>  conn.connectToServer(properties)<br>  mappinghome = conn.lookup("pbEjbMappingHome",<br>   "pbEjbTest/pbEjbMappingBeanSL",<br>   "pbejb.pbEjbMappingHome")<br>  mapping = mappinghome.create()<br>  ret = mapping.getChar()<br>  messagebox("char from EJB", ret)<br>catch (remoteexception re)<br>  messagebox("remoteexception", re.GetMessage())<br>catch (createexception ce)<br>  messagebox("createexception", ce.GetMessage())<br>end try</PRE></p>
<A NAME="TI5694"></A><h4>Unhandled exceptions</h4>
<A NAME="TI5695"></A><p>If no exception handler exists, or if the existing exception
handlers do not handle the exception, the SystemError event on the
Application object is executed. If the SystemError event has no
script, an application error occurs and the application is terminated.</p>

